package com.df.actions;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.df.managers.TypeManager;
import com.df.type.Type;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype") 
public class TypeAction extends ActionSupport{
	@Resource
	private TypeManager typeManager;
	public TypeManager getTypeManager() {
		return typeManager;
	}
	public void setTypeManager(TypeManager typeManager) {
		this.typeManager = typeManager;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	private Type type;
    private String page = "index";
    private int id;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	TypeAction(){}
	/**
	 * 查询栏目列表
	 */
	public String execute(){
	    ActionContext.getContext().put("pm", typeManager.list());
		return SUCCESS;
	}
	/**
	 * 添加栏目input
	 */
	public String addInput(){
		page = "add";
		return SUCCESS;
	}
	/**
	 * 添加栏目
	 */
	public String add(){
		typeManager.add(type);
		return "pub_add";
	}
	
	public String del(){
		typeManager.del(id);
		return "pub_del";
	}
	public String updateInput(){
		type = typeManager.getById(id);
		page = "add";
		return SUCCESS;
	}
	
	public String update(){
		typeManager.add(type);
		return "pub_update";
	}

}
